package com.huawei.classroom.student.h17;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.io.Closeable;
import java.io.FileReader;
import java.io.IOException;

public class BattleField {
    private static Properties read_ini = new Properties();
	private static List<Player> players = new ArrayList<Player>();
	static List<GameObject> gameObjects = new ArrayList<GameObject>();//attack（）用
	
	//读rules.ini
	public static void init(String path) {
		FileReader read = null;
		try {
			read = new FileReader(path);
			read_ini.load(read);
		}catch(IOException e) {
			System.out.println(e.getMessage());
			e.printStackTrace();
		}finally {
			close(read);
		}
	}
	//关闭输入流
	public static void close(Closeable inout) {
		if (inout != null) {
			try {
				inout.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	//返回先前创建的所有玩家
	public static List<Player> getAllPlayer() {
		return players;
	}
	//创建玩家
	public static void createPlayer(String playerNames) {
		players.add(new Player(playerNames));
	}
	//创建基地
	public static GameBase createGameBase(Player player, int x, int y) {
		GameBase base = new GameBase(player, x, y);
		gameObjects.add(base);
		return base;
	}
	//调用配置文件rules.ini的数据
	public static int getread_ini(String key) {
		String temp = read_ini.getProperty(key).replace(" ", "");
		return Integer.valueOf(temp);
	}
	
}
